/****** Object:  Stored Procedure [dbo].spChiTietPhieuNhapGet Script Date: 6/12/2012 ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[BaoCaoSanPhamKhachHangDaMua]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].BaoCaoSanPhamKhachHangDaMua
GO

/******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:					Description:
**		--------	--------				-----------------------------------
**		30/06/2012	SongTM					Innit created
*******************************************************************************/

CREATE PROCEDURE [dbo].BaoCaoSanPhamKhachHangDaMua
(
	@MaKhahHang nvarchar(6),
	@TuNgay datetime,
	@DenNgay datetime
)
WITH ENCRYPTION
AS

SET NOCOUNT ON

select
	*	
from
	tbl_KhachHang INNER JOIN tbl_PhieuXuat ON [tbl_KhachHang].MaKH = [tbl_PhieuXuat].MaKH
	INNER JOIN tbl_ChiTietPhieuXuat ON [tbl_PhieuXuat].SoPX = [tbl_ChiTietPhieuXuat].SoPX
	INNER JOIN tbl_LuuKho ON [tbl_ChiTietPhieuXuat].MaLuuKho=tbl_LuuKho.MaLuuKho
	INNER JOIN tbl_SanPham ON [tbl_SanPham].MaThuoc = tbl_LuuKho.MaThuoc
	INNER JOIN tbl_DonViTinh ON [tbl_DonViTinh].MaDonVi= [tbl_SanPham].maDonVi
WHERE
	TBL_KhachHang.maKH = @MaKhahHang
	And ((@TuNgay is null) or convert(date,@TuNgay)<=convert(date,tbl_PhieuXuat.NgayXuatkho))
	AND ((@DenNgay is null) or convert(date,@DenNgay)>=convert(date,tbl_PhieuXuat.NgayXuatkho))
	
	SELECT * FROM tbl_Congty
GO


--GRANT EXECUTE ON [dbo].[spChiTietPhieuNhapGet] TO [sa]
--GO
